package com.example.administrator.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Main2Activity extends AppCompatActivity {
/* 定义控件属性（布局文件中相关的控件）*/
    private EditText ed_name,ed_phone;
    private Button btn_submit,btn_reset;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        /*关联布局文件*/
        setContentView(R.layout.activity_main2);
        /*关联控件*/
        ed_name=findViewById(R.id.editText);
        ed_phone=findViewById(R.id.editText2);
        btn_submit=findViewById(R.id.button);
        btn_reset=findViewById(R.id.button2);
        /*按钮的点击事件*/

        /*事件*/
        View.OnClickListener click=new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            String s=ed_name.getText().toString()+" "+ed_phone.getText().toString();
            Toast.makeText(Main2Activity.this,s,Toast.LENGTH_SHORT).show();
            }
        };

        View.OnClickListener click1=new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ed_name.setText("");
                ed_phone.setText("");
                ed_name.requestFocus();
            }
        };
        /*按钮绑定上事件*/
        btn_submit.setOnClickListener(click);
        btn_reset.setOnClickListener(click1);
    }
}
